package br.com.lh.urabuilder.business.bootstrap
{
	import br.com.lh.urabuilder.event.LoadUraEvent;
	import br.com.lh.urabuilder.event.LoadUraResourceEvent;
	import br.com.lh.urabuilder.event.dispatcher.IEventDispatcher2;
	import br.com.lh.urabuilder.event.factory.UraEventFactory;
	import br.com.lh.urabuilder.model.UraModelLocator;
	
	import mx.containers.Canvas;
	import mx.controls.Alert;
	
	/**
	 * This class will be called when the application gets started, performing 
	 * the initial instantiation and populating the data from the server side.
	 * 
	 * @author Luiz Henrique
	 * 
	 */
	public class UraBuilderLoader
	{
		public var eventDispatcher:IEventDispatcher2;
		public var eventFactory:UraEventFactory;
		
		
		public function UraBuilderLoader(eventDispatcher:IEventDispatcher2,eventFactory:UraEventFactory){
			this.eventDispatcher = eventDispatcher;
			this.eventFactory = eventFactory;
		}
		
		
		public function doLoad(uraId:String,sessionId:String,canvas:Canvas):UraModelLocator{
			var modelLocator:UraModelLocator = UraModelLocator.getInstance(canvas,sessionId);
			if (sessionId == null){
				return modelLocator;
			}
			if (uraId !=null && uraId != "-1"){
				eventDispatcher.dispatchEvent(eventFactory.getLoadUraEvent(LoadUraEvent.EVENT_LOAD_URA_ACTION,sessionId,uraId));
			}else{
				eventDispatcher.dispatchEvent(eventFactory.getLoadUraEvent(LoadUraResourceEvent.EVENT_LOAD_URA_RESOURCE_ACTION,sessionId,uraId));
			}
			return modelLocator;
		}

	}
}